package com.mywork.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ciko.code.base.BaseActicity;
import com.mywork.R;


/**
 * Created by HP on 2016/2/16.
 */
public class PollSurveyActivity
        extends
        BaseActicity
{
	ListView				  llPollSurvey;
	private Context			  context;
	private Intent			  intent;
	private PollSurveyAdapter adapter;
	private String            title  =  "";
	@Override
	protected void initView() {
		context = this;
		llPollSurvey = (ListView) findViewById(R.id.ll_poll_survey);
		
	}
	
	@Override
	protected void initTopBar() {
		if (getIntent().getExtras().containsKey("title")) {
			title = getIntent().getStringExtra("title");
		}
		setTitle(title);
		enableNavLeftImg();
		enableNavRightImg(R.drawable.icon_add);
		setOnNavRightClickListener(new OnNavRightClickListener()
		{
			@Override
			public void onNavRightClick() {
				intent = new Intent(PollSurveyActivity.this, SubmitPollActivity.class);
				startActivity(intent);
			}
		});
	}
	
	@Override
	protected void initLayout() {
		setContentView(R.layout.activity_poll_survey);
	}
	
	@Override
	protected void initAdapter() {
		adapter = new PollSurveyAdapter();
		llPollSurvey.setAdapter(adapter);
	}
	
	@Override
	protected void initDates() {
	
	}
	
	@Override
	protected void initListener() {
//		llPollSurvey.setOnItemClickListener(new AdapterView.OnItemClickListener()
//		{
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//				intent = new Intent(PollSurveyActivity.this, PollSurveyDetailActivity.class);
//				startActivity(intent);
//			}
//		});
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
	
	private class PollSurveyAdapter
	        extends
	        BaseAdapter
	{
		
		private HolderView holder;
		
		@Override
		public int getCount() {
			return 3;
		}
		
		@Override
		public Object getItem(int position) {
			return null;
		}
		
		@Override
		public long getItemId(int position) {
			return 0;
		}
		
		@Override
		public View getView(final int position, View view, ViewGroup parent) {
			if (view == null)
			{
				holder = new HolderView();
				view = View.inflate(context, R.layout.poll_survey_item, null);
				holder.tvPollNow = (TextView) view.findViewById(R.id.poll_right_now);
				holder.llChooses = (LinearLayout) view.findViewById(R.id.ll_chooses);
				holder.tvStatus = (TextView) view.findViewById(R.id.tv_status);
				view.setTag(holder);
				
			}
			else
			{
				holder = (HolderView) view.getTag();
			}
			switch (position) {
				case 0:
					holder.tvPollNow.setText("立即投票");
					holder.llChooses.setVisibility(View.VISIBLE);
					holder.tvStatus.setText("进行中");
					holder.tvStatus.setBackgroundColor(0xfff1bc06);
					break;
				case 1:
					holder.tvPollNow.setText("已投票，查看结果");
					holder.llChooses.setVisibility(View.VISIBLE);
					holder.tvStatus.setText("进行中");
					holder.tvStatus.setBackgroundColor(0xfff1bc06);
					break;
				case 2:
					holder.tvPollNow.setText("已投票，查看结果");
					holder.llChooses.setVisibility(View.GONE);
					holder.tvStatus.setText("已结束");
					holder.tvStatus.setBackgroundColor(0xffc4c4c4);
					break;
					
			}
			holder.tvPollNow.setOnClickListener(new View.OnClickListener()
			{
				@Override
				public void onClick(View v) {
					intent = new Intent(PollSurveyActivity.this, PollSurveyDetailActivity.class);
					intent.putExtra("position", position);
					startActivity(intent);
				}
			});
			return view;
		}
	}
	
	private class HolderView
	{
		TextView	 tvPollNow, tvStatus;
		LinearLayout llChooses;
	}
}
